This section shows how to generate SCA Java based services from a choreography, add implementation details to the service and then verify it against scenarios.
Generating SCA Java based Services
When a choreography description has been created, it is possible to generate a SCA Java implementation (and associated WSDL files and SCA composite descriptor) for one or more of the participants defined within the choreography. To try this out, select the Savara->Generate->Service menu item from the popup menu associated with the architecture/PurchaseGoods.bpmn.
This will display a dialog listing the possible services that can be generated from this choreography, with a proposed Eclipse project name, and the option to select a service type (in this case SCA Java).
Press the 'Ok' button and this will create a Java project for the Store, Logistics and CreditAgency participants.
Each project will be generated as a Java project, containing the relevant Java interfaces and classes for the service implementation, the WSDL and XSD files for the public service interface, and the SCA composite descriptor.
Verifying the SCA Java implementation against a Scenario
In a previous section of the document, it showed how to use the Scenario (that represents a particular use case or requirement) to verify an architectural model (or choreography). The same scenarios can be used to test the service implementations generated from those architectural models or designs.
For example, to test the SCA Java implementation for the Store participants, you open the requirements/SuccessfulPurchase.scn scenario and press the green "play" button in the toolbar. This will show the 'scenario simulation' dialog. Then for the Store role, select the relevant composite file, so for the Store role locate the Store.composite file in the PurchaseGoods-Store/src/main/resources folder:
When the SCA composite has been selected, then it will automatically set the simulator to be "SCA simulator" and clear the model role - this is because the model role is not relevant as the service implementation represents a single role, rather than a collection of roles as in the case of a choreography being used for the model.
Next press the "Simulate" button. Unlike the verification against a choreography model, which is pure simulation, when the SCA simulator is used and configured with a particular SCA composite file, then the simulation is performed by executing the service implementation. The simulation output is the same though:
Note however, before being able to verify the SCA Store implementation through simulation, you will need to implement the service logic. Initially it will be created as a skeleton. The following is a completed version of the org.savara.examples.store.StoreImpl class:
package org.savara.examples.store;
import java.math.BigInteger;
import java.util.logging.Logger;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
import org.savara.examples.creditagency.CreditAgency;
import org.savara.examples.logistics.Logistics;
import org.jboss.examples.store.AccountNotFoundType;
import org.oasisopen.sca.annotation.Reference;
/**
* This class was generated by Apache CXF 2.4.0
* 2012-02-08T10:25:28.453Z
* Generated source version: 2.4.0
*
*/
@javax.jws.WebService(
serviceName = "StoreService",
portName = "StorePort",
targetNamespace = "http://www.savara.org/examples/Store",
wsdlLocation = "wsdl/PurchaseGoods_Store.wsdl",
endpointInterface = "org.savara.examples.store.Store")
public class StoreImpl implements Store {
private static final Logger LOG = Logger.getLogger(StoreImpl.class.getName());
@Reference
public CreditAgency creditAgency;
@Reference
public Logistics logistics;
/* (non-Javadoc)
* @see org.savara.examples.store.Store#buy(org.jboss.examples.store.BuyRequestType content )*
*/
public org.jboss.examples.store.BuyConfirmedType buy(org.jboss.examples.store.BuyRequestType content) throws InsufficientCreditFault , AccountNotFoundFault {
LOG.info("Executing operation buy");
System.out.println(content);
try {
org.jboss.examples.creditagency.CreditCheckType check=
new org.jboss.examples.creditagency.CreditCheckType();
check.setId(content.getId());
check.setCustomer("C104536");
org.jboss.examples.creditagency.CreditRatingType rating=
creditAgency.creditCheck(check);
System.out.println("RATING="+rating);
if (rating.getRating().intValue() > 5) {
org.jboss.examples.logistics.DeliveryRequestType deliveryRequest=
new org.jboss.examples.logistics.DeliveryRequestType();
deliveryRequest.setId(content.getId());
deliveryRequest.setAddress("1001 Acme Street");
org.jboss.examples.logistics.DeliveryConfirmedType delivery=
logistics.delivery(deliveryRequest);
org.jboss.examples.store.BuyConfirmedType _return =
new org.jboss.examples.store.BuyConfirmedType();
_return.setId("1");
_return.setAmount(BigInteger.valueOf(500));
return _return;
} else {
org.jboss.examples.store.BuyFailedType buyFailed =
new org.jboss.examples.store.BuyFailedType();
buyFailed.setId("1");
throw new org.savara.examples.store.InsufficientCreditFault("Buy failed", buyFailed);
}
} catch(org.savara.examples.creditagency.CustomerUnknownFault cuf) {
AccountNotFoundType anft=new AccountNotFoundType();
anft.setId(content.getId());
anft.setReason("Don't know you");
throw new AccountNotFoundFault("Account not found", anft);
}
}
}